home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_03
/
kamradt
/
cpyonwrt.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-07
|
525b
|
33 lines
class String {
// the contents of the string
// class from Figure 5.
...
// this indexing operator could
// modify the string
char &operator[](int i)
{
if(imp->count > 1)
Split();
return imp->ptr[i];
}
// This indexing operator won't
// modify, don't split.
char operator[](int i) const
{
return imp->ptr[i];
}
private:
void Split()
{
// Create private copy:
imp->count--;
imp = new
StringImp(imp->ptr);
}
};